
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>校园论坛管理系统</title>
<meta name="keywords" content="layuiAdmin、layuiadmin好用吗、layuiadmin 教程、layuiadmin套餐版、layuiadmin官方下载、layuiadmin官方模板" />
<meta name="description" content="layuiadmin官方iframe标准版采用前后端分离开发模式,因此你无需将其放置在你的服务端,layuiadmin是目前最流行最方便的UI轻量级框架,使用这款layuiadmin可以方便用户自定义后台界面模板,适用于各个企业网站、博客、论坛、社区类型layuiadmin后台管理模板。" />
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="./layui/css/layui.css" media="all">
<link rel="stylesheet" href="./layui/css/admin.css" media="all">
<!--  <link rel="stylesheet" href="./layui/css/layui_dist.css" media="all">-->
<link rel="stylesheet" href="./CSS/index.css">
</head>
<body class="layui-layout-body">
  <div id="LAY_app" >
    <div class="layui-layout layui-layout-admin">
      <div class="layui-header">
        <!-- 头部区域 -->
        <ul class="layui-nav layui-layout-left">
          <li class="layui-nav-item layadmin-flexible" lay-unselect>
            <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">
              <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
            </a>
          </li>
          <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="https://www.layui1.com/" target="_blank" title="前台">
              <i class="layui-icon layui-icon-website"></i>
            </a>
          </li>
          <li class="layui-nav-item" lay-unselect>
            <a href="javascript:;" layadmin-event="refresh" title="刷新">
              <i class="layui-icon layui-icon-refresh-3"></i>
            </a>
          </li>
          <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <input type="text" placeholder="搜索..." autocomplete="off" class="layui-input layui-input-search" layadmin-event="serach" lay-action="template/search.html?keywords="> 
          </li>
        </ul>
        <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">
          
          <li class="layui-nav-item" lay-unselect>
            <a lay-href="message/index.html" layadmin-event="message" lay-text="消息中心">
              <i class="layui-icon layui-icon-notice"></i>  
              
              <!-- 如果有新消息，则显示小圆点 -->
              <span class="layui-badge-dot" id="messageDot"></span>
            </a>
          </li>
          <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="javascript:;" layadmin-event="note">
              <i class="layui-icon layui-icon-note"></i>
            </a>
          </li>
          <li class="layui-nav-item layui-hide-xs" lay-unselect >
            <a href="javascript:;" layadmin-event="fullscreen">
              <i class="layui-icon layui-icon-screen-full"></i>
            </a>
          </li>
          <li class="layui-nav-item" lay-unselect>
           <a href="javascript:;"><img src="https://campusforum-web.oss-cn-beijing.aliyuncs.com/06e88419-9f4c-4429-873b-67218410c613.JPG" class="layui-nav-img"><a href="javascript:;">
            <cite id="usname">贤心</cite>
          </a></a> 
            
            <dl class="layui-nav-child layui-nav-set">
              <dd lay-href="set/info.html" ><a lay-tips="基本资料">基本资料</a></dd>
              <dd lay-href="set/password.html" ><a lay-tips="修改密码">修改密码</a></dd>
              <hr>
              <dd layadmin-event="logout" style="text-align: center;" ><a lay-tips="退出">退出</a></dd>
            </dl>
          </li>
          
          <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="javascript:;" layadmin-event="about"><i class="layui-icon layui-icon-more-vertical"></i></a>
          </li>
          <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-unselect>
            <a href="javascript:;" layadmin-event="more"><i class="layui-icon layui-icon-more-vertical"></i></a>
          </li>
        </ul>
      </div>
      
      <!-- 侧边菜单 -->
      <div class="layui-side layui-side-menu">
        <div class="layui-side-scroll">
          <div class="layui-logo" lay-href="home/console.html">
            <span>校园论坛管理系统</span>
          </div>
          
          <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">
            <li data-name="home" class="layui-nav-item layui-nav-itemed layui-this">
              <a href="javascript:;" lay-tips="主页" data-index="home/console.html">
                <i class="layui-icon layui-icon-home"></i>
                <cite>主页</cite>
              </a>
            </li>
            <li data-name="user" class="layui-nav-item">
              <a href="javascript:;" lay-tips="用户管理" data-index="user/index.html">
                <i class="layui-icon layui-icon-user"></i>
                <cite>用户管理</cite>
              </a>
            </li>
            <li data-name="department" class="layui-nav-item">
              <a href="javascript:;" lay-tips="院系管理" data-index="department/index.html">
                <i class="layui-icon layui-icon-template-1"></i>
                <cite>院系管理</cite>
              </a>
            </li>
            <li data-name="article" class="layui-nav-item">
              <a href="javascript:;" lay-tips="文章管理" data-index="article/index.html">
                <i class="layui-icon layui-icon-template"></i>
                <cite>文章管理</cite>
              </a>
            </li>
            <li data-name="activity" class="layui-nav-item">
              <a href="javascript:;" lay-tips="活动管理">
                <i class="layui-icon layui-icon-flag"></i>
                <cite>活动管理</cite>
              </a>
              <dl class="layui-nav-child">
                <dd><a href="javascript:;" data-index="activity/index.html" lay-tips="活动信息">活动信息</a></dd>
                <dd><a href="javascript:;" data-index="actpartin/index.html" lay-tips="活动参与">活动参与</a></dd>
              </dl>
            </li>
            <li data-name="activity" class="layui-nav-item">
              <a href="javascript:;" lay-tips="分类管理">
                <i class="layui-icon layui-icon-note"></i>
                <cite>分类管理</cite>
              </a>
              <dl class="layui-nav-child">
                <dd><a href="javascript:;" data-index="articlecategory/index.html" lay-tips="文章分类">文章分类</a></dd>
                <dd><a href="javascript:;" data-index="activitytag/index.html" lay-tips="活动分类">活动分类</a></dd>
              </dl>
            </li>
            <li data-name="commit" class="layui-nav-item">
              <a href="javascript:;" lay-tips="评论管理" data-index="commit/index.html">
                <i class="layui-icon layui-icon-dialogue"></i>
                <cite>评论管理</cite>
              </a>
            </li>
            <li data-name="rbac" class="layui-nav-item">
              <a href="javascript:;" lay-tips="角色与权限管理" data-index="rbac/index.html">
                <i class="layui-icon layui-icon-key">&#xe683;</i>
                <cite>角色与权限管理</cite>
              </a>
            </li>
            <!-- <li data-name="loginfo" class="layui-nav-item">
              <a href="javascript:;" lay-tips="日志管理" data-index="loginfo/index.html">
                <i class="layui-icon layui-icon-form"></i>
                <cite>日志管理</cite>
              </a>
            </li> -->
            
          </ul>
        </div>
      </div>

      <!-- 页面标签 -->
      <div class="layadmin-pagetabs" id="LAY_app_tabs">
        <div class="layui-icon layadmin-tabs-control layui-icon-prev" layadmin-event="leftPage"></div>
        <div class="layui-icon layadmin-tabs-control layui-icon-next" layadmin-event="rightPage"></div>
        <div class="layui-icon layadmin-tabs-control layui-icon-down">
          <ul class="layui-nav layadmin-tabs-select" lay-filter="layadmin-pagetabs-nav">
            <li class="layui-nav-item" lay-unselect>
              <a href="javascript:;"></a>
              <dl class="layui-nav-child layui-anim-fadein">
                <dd layadmin-event="closeThisTabs"><a href="javascript:;">关闭当前标签页</a></dd>
                <dd layadmin-event="closeOtherTabs"><a href="javascript:;">关闭其它标签页</a></dd>
                <dd layadmin-event="closeAllTabs"><a href="javascript:;">关闭全部标签页</a></dd>
              </dl>
            </li>
          </ul>
        </div>
        <div class="layui-tab" lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">
          <ul class="layui-tab-title" id="LAY_app_tabsheader">
            <li lay-id="home/console.html" lay-attr="home/console.html" class="layui-this"><i class="layui-icon layui-icon-home"></i></li>
          </ul>
        </div>
      </div>
      
      
      <!-- 主体内容 -->
      <div class="layui-body" id="LAY_app_body">
        <div class="layadmin-tabsbody-item layui-show">
          <iframe src="home/console.html" frameborder="0" class="layadmin-iframe"></iframe>
        </div>
      </div>
      
      <!-- 辅助元素，一般用于移动设备下遮罩 -->
      <div class="layadmin-body-shade" layadmin-event="shade"></div>
    </div>

  </div>


  <div class="layui-layer-page layui-layer-admin layadmin-note layui-anim layui-anim-upbit" id="layui-layer1" type="page" times="1" showtime="0" contype="string">
    <div class="layui-layer-title" style="cursor: move;">便签</div>
    <div id="LAY_adminNote" class="layui-layer-content">
      <textarea placeholder="内容" id="noteTextarea"></textarea>
    </div>
    <span class="layui-layer-setwin"></span>
  </div>


<script src="./JS/axios.js"></script>
  <script src="./JS/utils/request.js"></script>
  <script src="./JS/utils/auth.js"></script>
  <script src="./layui/layui.all.js"></script>
  <!-- <script src="./layui/lay/modules/jquery.js"></script> -->
  <script>
  layui.use(['element','jquery','layer'],function () {
    var element = layui.element; // 获取 layui 的 element 模块
    var $=layui.jquery;
    var layer = layui.layer
    $('.layui-nav-img').attr("src",localStorage.getItem('avatar'))
    $('#usname').text(localStorage.getItem('username'))
  //遍历左侧导航条的链接 实现导航链条对应右侧页面
    $(".layui-side li>a").each(function(index,e){
					//当点击链接时
					$(e).click(function(){
            // console.log(e);
            
            var url = e.getAttribute('data-index');
            var title = e.getAttribute('lay-tips');
            // console.log(title);
            
            if(title !='分类管理' && title !='活动管理'){
          // 检查是否已经存在该标签页
          var tabs = document.querySelectorAll('#LAY_app_tabsheader li');
                var existingTab = Array.from(tabs).find(function(tab) {
                  return tab.getAttribute('lay-id') === url;
                });

                if (!existingTab) {
                  // 如果不存在，添加新的标签页
                //对应页面进行改变并添加对应标签
                      $(".layui-body iframe").attr("src",$(this).attr("data-index"));
                      element.tabAdd('layadmin-layout-tabs',{
                        title:title,
                        content:'<iframe src="' + url + '" frameborder="0" class="layui-tab-frame"></iframe>',
                        id:url
                      })
                      element.tabChange('layadmin-layout-tabs',url)
                      // console.log(url);
                }else{
                  element.tabChange('layadmin-layout-tabs',url)
                }
            }
             
	})
				});

// 遍历左侧二层导航条的链接 实现导航链条对应右侧页面
$("dl dd>a").each(function(index,e){
					//当点击链接时
					$(e).click(function(){
            var url = e.getAttribute('data-index');
            var title = e.getAttribute('lay-tips');
            console.log(url);
            console.log(title);
            
            if(title !='基本资料' && title !='修改密码' && title!='退出'){      
             // 检查是否已经存在该标签页
      var tabs = document.querySelectorAll('#LAY_app_tabsheader li');
      var existingTab = Array.from(tabs).find(function(tab) {
        return tab.getAttribute('lay-id') === url;
      });

      if (!existingTab) {
        // 如果不存在，添加新的标签页
       //对应页面进行改变并添加对应标签
						$(".layui-body iframe").attr("src",$(this).attr("data-index"));
            element.tabAdd('layadmin-layout-tabs',{
              title:title,
              content:'<iframe src="' + url + '" frameborder="0" class="layui-tab-frame"></iframe>',
              id:url
            })
            element.tabChange('layadmin-layout-tabs',url)
            // console.log(url);
      }else{
        element.tabChange('layadmin-layout-tabs',url)
      }
    }
	})
				});

  // 实现侧边导航栏伸缩
    $("#LAY_app_flexible").click(function () {
      console.log($(this))
      $('#LAY_app').toggleClass('layadmin-side-shrink')
    });
 // 实现页面刷新
    $('.layui-icon-refresh-3').click(function() {
    location.reload();
    });
    
  // 实现全屏
  // 获取全屏按钮元素
  var fullscreenBtn = $('a[layadmin-event="fullscreen"]');
    var fullscreenIcon = fullscreenBtn.find('i');
    
    // 监听全屏状态变化
    document.addEventListener('fullscreenchange', handleFullscreenChange);
    document.addEventListener('webkitfullscreenchange', handleFullscreenChange); // Safari
    document.addEventListener('mozfullscreenchange', handleFullscreenChange);    // Firefox
    document.addEventListener('MSFullscreenChange', handleFullscreenChange);     // IE11

    // 绑定点击事件
    fullscreenBtn.on('click', toggleFullscreen);

    // 全屏切换函数
    function toggleFullscreen() {
        if (!document.fullscreenElement &&    // 标准语法
            !document.mozFullScreenElement && 
            !document.webkitFullscreenElement && 
            !document.msFullscreenElement ) { 
            // 进入全屏
            var element = document.documentElement;
            if (element.requestFullscreen) {
                element.requestFullscreen();
            } else if (element.mozRequestFullScreen) { // Firefox
                element.mozRequestFullScreen();
            } else if (element.webkitRequestFullscreen) { // Chrome,Safari
                element.webkitRequestFullscreen();
            } else if (element.msRequestFullscreen) { // IE11
                element.msRequestFullscreen();
            }
        } else {
            // 退出全屏
            if (document.exitFullscreen) {
                document.exitFullscreen();
            } else if (document.mozCancelFullScreen) { // Firefox
                document.mozCancelFullScreen();
            } else if (document.webkitExitFullscreen) { // Chrome,Safari
                document.webkitExitFullscreen();
            } else if (document.msExitFullscreen) { // IE11
                document.msExitFullscreen();
            }
        }
    }

    // 全屏状态变化回调
    function handleFullscreenChange() {
        if (document.fullscreenElement || 
            document.mozFullScreenElement ||
            document.webkitFullscreenElement ||
            document.msFullscreenElement) {
            // 全屏状态：切换为退出图标
            fullscreenIcon.removeClass('layui-icon-screen-full')
                          .addClass('layui-icon-screen-restore');
        } else {
            // 非全屏状态：恢复原图标
            fullscreenIcon.removeClass('layui-icon-screen-restore')
                          .addClass('layui-icon-screen-full');
        }
    }
// 动态切换页面标签
element.on('tab',function(data){
  $(".layui-body iframe").attr("src",$(this).attr("lay-id"));
        // console.log("切换至 lay-id:", layId);
})

// 监听页面标签的控制按钮事件
document.addEventListener('click', function(event) {
    var target = event.target;
    var parent = target.closest('dd'); // 获取点击的 <dd> 标签

    if (parent && parent.getAttribute('layadmin-event')) {
      var action = parent.getAttribute('layadmin-event');
      var currentTab = document.querySelector('#LAY_app_tabsheader .layui-this');
          var layid = $(currentTab).attr("lay-id");
          var homeurl = $(".layui-nav-tree > li a").attr("data-index") 
          // 获取全部标签
          var tabs = document.querySelectorAll('#LAY_app_tabsheader li');
      switch (action) {
        case 'closeThisTabs':
          // 关闭当前标签页
          
          /*当前标签的lay-id不等于侧边栏第一个元素的data-index的值
          保留默认主页栏*/
          if (currentTab && layid!=homeurl) {
            var currentId = currentTab.getAttribute('lay-id');
            element.tabDelete('layadmin-layout-tabs', currentId);
          }
          break;

        case 'closeOtherTabs':
          // 关闭其他标签页
          Array.from(tabs).forEach(function(tab) {
            if (!tab.classList.contains('layui-this') && $(tab).attr("lay-id")!=homeurl) {
              var tabId = tab.getAttribute('lay-id');
              element.tabDelete('layadmin-layout-tabs', tabId);
            }
          });
          break;

        case 'closeAllTabs':
          // 关闭全部标签页
          Array.from(tabs).forEach(function(tab) {
            if ($(tab).attr("lay-id")!=homeurl) {
              var tabId = tab.getAttribute('lay-id');
              element.tabDelete('layadmin-layout-tabs', tabId);
            }
          });
          break;
      }
    }
  });
  // 便签的显示与隐藏切换
  $('a[layadmin-event="note"]').click(function(){
    // console.log($(this));
    $('.layadmin-note').toggleClass("show")
  })

  // 消息管理页面（js逻辑同上面侧边栏）
$('a[layadmin-event="message"]').click(function(){
            var url = $(this).attr('lay-href')
            var title = $(this).attr('lay-text')
             // 检查是否已经存在该标签页
      var tabs = document.querySelectorAll('#LAY_app_tabsheader li');
      var existingTab = Array.from(tabs).find(function(tab) {
        return tab.getAttribute('lay-id') === url;
      });

      if (!existingTab) {
        // 如果不存在，添加新的标签页
       //对应页面进行改变并添加对应标签
						$(".layui-body iframe").attr("src",$(this).attr("data-index"));
            element.tabAdd('layadmin-layout-tabs',{
              title:title,
              content:'<iframe src="' + url + '" frameborder="0" class="layui-tab-frame"></iframe>',
              id:url
            })
            element.tabChange('layadmin-layout-tabs',url)
            // console.log(url);
      }else{
        element.tabChange('layadmin-layout-tabs',url)
      }
	})

// 个人信息编辑
$(".layui-nav-set dd").each(function(index,e){
					//当点击链接时
					$(e).click(function(){
            var url = $(this).attr("lay-href");
            var title = e.querySelector('a').innerText;
            // console.log(title);
       if(title!='退出'){
       // 检查是否已经存在该标签页
       var tabs = document.querySelectorAll('#LAY_app_tabsheader li');
      var existingTab = Array.from(tabs).find(function(tab) {
        return tab.getAttribute('lay-id') === url;
      });

      if (!existingTab) {
        // 如果不存在，添加新的标签页
       //对应页面进行改变并添加对应标签
						$(".layui-body iframe").attr("src",$(this).attr("data-index"));
            element.tabAdd('layadmin-layout-tabs',{
              title:title,
              content:'<iframe src="' + url + '" frameborder="0" class="layui-tab-frame"></iframe>',
              id:url
            })
            element.tabChange('layadmin-layout-tabs',url)
            // console.log(url);
      }else{
        element.tabChange('layadmin-layout-tabs',url)
      }
       }     
      
	})

});

$(function(){
  var articlecount = localStorage.getItem('article_count');
  var activitycount = localStorage.getItem('activity_count');
  var sum = parseInt(articlecount, 10) + parseInt(activitycount, 10);
  console.log(activitycount,articlecount,sum);
  if(sum===0){
    $('#messageDot').hide()
  }
})
// 页面加载时读取
setInterval(function(){  
  var articlecount = localStorage.getItem('article_count');
  var activitycount = localStorage.getItem('activity_count');
  var sum = parseInt(articlecount, 10) + parseInt(activitycount, 10);
  console.log(activitycount,articlecount,sum);
  if(sum===0){
    $('#messageDot').hide()
  }
},50000);
$(function(){    
$.ajax({
                url: '/activities/AuditList',
                type: 'get',
                contentType: 'application/json',
                headers:{
              'Authorization':localStorage.getItem('token')
    },
                success: function (res) {
                    console.log(res);
                    if(res.data.totalCount>0){
                      localStorage.setItem('activity_count',res.data.totalCount)
                    $('#messageDot').show()
                    
  }
                },
                error: '请求失败'
            });
          });  
          $(function(){    
$.ajax({
                url: '/articles/AuditList',
                type: 'get',
                contentType: 'application/json',
                headers:{
              'Authorization':localStorage.getItem('token')
    },
                success: function (res) {
                    console.log(res);
           if(res.msg ==='NOT_LOGIN'){
            parent.location.href='./login.html'
            localStorage.clear()
          }else if(res.data.totalCount>0){
                      localStorage.setItem('article_count',res.data.totalCount)
                    $('#messageDot').show()
  }
                },
                error: '请求失败'
            });
          }); 

          // 页面加载时从localStorage中读取内容并显示
window.onload = function() {
  const textarea = document.getElementById('noteTextarea');
  const savedContent = localStorage.getItem('noteContent');
  if (savedContent) {
    textarea.value = savedContent;
  }
};
// 监听textarea的输入事件，实时保存到localStorage
const textarea = document.getElementById('noteTextarea');
textarea.addEventListener('input', function() {
  const content = textarea.value;
  localStorage.setItem('noteContent', content);
});

// 退出登录
$('[layadmin-event="logout"]').click(function(){
   // 使用confirm确认框
   const isConfirm = confirm('确定要退出登录吗？');
   if(isConfirm) {
    
        // 清除本地存储
        localStorage.removeItem('token');
        localStorage.removeItem('username');
        localStorage.removeItem('avatar');
        localStorage.removeItem('userId');
        // 跳转到登录页
        window.location.href = '/login.html';
      } else {
        alert('退出失败');
      }  
})
  })

  </script>

<script>
  
</script>

</body>
</html>


